// Loesung_von_Aufgabe_3.7_1_Vektorfeld

float Q = 0.6; // Ladung in Coulomb
float epsilon = 8.85418782E-12; // elektrische Feldkonstante in AsV^-1m^-1
float winkel; // Winkel im Bogenmaß
float r1 = 2; // Abstand in m
float r2 = 3; // Abstand in m
float r3 = 4; // Abstand in m
float pr1 = 200; // Abstand in Pixel
float pr2 = 300; // Abstand in Pixel
float pr3 = 400; // Abstand in Pixel
float E1; // elektrische Feldstärke in V/m
float E2; // elektrische Feldstärke in V/m
float E3; // elektrische Feldstärke in V/m
float pE1; // elektrische Feldstärke in Pixel
float pE2; // elektrische Feldstärke in Pixel
float pE3; // elektrische Feldstärke in Pixel

void setup()
{
  size(900, 900);
  background(255);

  // Maßstab für r
  stroke(0);
  strokeWeight(5);
  line(50, 800, 150, 800);
  fill(0);
  textSize(20);
  textAlign(CENTER);
  text("r = 1,0 m", 100, 830); 

  // Maßstab für E
  stroke(255, 0, 0);
  strokeWeight(5);
  line(725, 800, 836, 800);
  fill(255, 0, 0);
  textSize(20);
  textAlign(CENTER);
  text("E = 1,5*10^9 V/m", 775, 830);
}

void draw()
{
  // Berechnen der elektrischen Feldstärke
  E1 = Q/(4*PI*epsilon*r1*r1);
  E2 = Q/(4*PI*epsilon*r2*r2);
  E3 = Q/(4*PI*epsilon*r3*r3);

  // Umrechnung der Feldstärke in Pixelwerte
  pE1 = E1/(1.7E7);
  pE2 = E2/(1.7E7);
  pE3 = E3/(1.7E7);

  // Verschiebung des Ursprungs in die Fenstermitte
  translate(width/2, height/2);

  // positive Ladung zeichnen
  fill(255, 0, 0);
  noStroke();
  ellipse(0, 0, 50, 50);

  if (winkel <= 2*PI) 
  {
    winkel = winkel + 2*PI/30; // Winkelzuwachs um 30 Vektorpfeile zu erhalten

    rotate(winkel); // Rotation des Koordinatensystems mit den folgenden Zeichnungsobjekten

    // Vektorpfeile zeichnen
    stroke(255, 0, 0);
    strokeWeight(3);
    line(pr1, 0, pr1+pE1, 0);
    triangle(pr1+pE1-10, -2, pr1+pE1, 0, pr1+pE1-10, 2);
    line(pr2, 0, pr2+pE2, 0);
    triangle(pr2+pE2-10, -2, pr2+pE2, 0, pr2+pE2-10, 2);
    line(pr3, 0, pr3+pE3, 0);
    triangle(pr3+pE3-10, -2, pr3+pE3, 0, pr3+pE3-10, 2);

    stroke(0);
    strokeWeight(5);
    point(pr1, 0);
    point(pr2, 0);
    point(pr3, 0);
  }
}